$(function() {
	var tableSource = new $.jqx.dataAdapter({
		dataType : "json",
		dataFields : [ {
			name : "id",
			type : "int"
		}, {
			name : "name",
			type : "string"
		} ],
		id : "id",
		url : "intcategory/all.do"
	});
	$("#dataTable").jqxDataTable({
		width : "100%",
		source : tableSource,
		pageable : true,
		pageSize : 15,
		serverProcessing : true,
		pagerButtonsCount : 10,
		columnsResize : true,
		sortable : true,
		columns : [ {
			text : "序号",
			width : 50,
			cellsRenderer : function(row) {
				return (row + 1).toString();
			}
		}, {
			text : "名称",
			dataField : "name"
		} ],
	});
	$("#dataTable")
			.on(
					"rowDoubleClick",
					function(info, args) {
						if (args && args.flag) {
							info = args;
						}
						editingIndex = info.args.index;
						editingData = info.args.row;
						_editerIndex = layer
								.open({
									id : "intcategoryEditer",
									title : "添加国际分类",
									type : 1,
									skin : "layui-layer-rim",
									area : [ "360px", "130px" ],
									content : '<form id="intcategory-editer" class="form" method="post" enctype="multipart/form-data" style="height: 100%;overflow: auto;">'
											+ '<input type="hidden" name="id" />'
											+ '<input type="hidden" name="submit-url" value="intcategory/add.do" />'
											+ '<div class="input-box">'
											+ '<label class="from-label update" for="name">类型名称：</label>'
											+ '<input type="text" name="name" allowBlank="false" class="form-control" placeholder="类型名称" />'
											+ '</div>'
											+ '</form>'
											+ '<div class="form" style="position: absolute;bottom: 0px;width: 100%;text-align: right;background-color: #DDD;">'
											+ '<input type="button" class="btn btn-sm btn-success" onclick="submitEditer(this)" value="保存"/>'
											+ '<input type="button" class="btn btn-sm btn-info" onclick="closeEditer(this)" value="返回"/>'
											+ '</div>',
								});
					});

	$("#addRecommendGoods").on("click", function() {
		// 判断是否选择了一行数据
		var rows = $("#dataTable").jqxDataTable("getSelection");
		if (rows.length < 1) {
			layer.msg("至少选择一行数据", {
				shift : 6,
				offset : "5%"
			});
			return null;
		}
		_editerIndex = layer.open({
			id : "addRecommendGoods",
			title : "添加全球购商品推荐",
			type : 1,
			skin : "layui-layer-rim",
			area : [ "900px", "500px" ],
			content : '<div id="globalGoods"></div>',
		});
		buildGoodsSelect(rows);
	});
});

function buildGoodsSelect(rows) {
	var globalUrl = "goods/rcmdGlobalGoods.do?id=" + rows[0].id;
	var globalSource = {
		datatype : "json",
		datafields : [ {
			name : 'uuid'
		}, {
			name : 'name'
		}, {
			name : 'qqgBoutique'
		} ],
		url : globalUrl,
		async : false
	};

	var globaldataAdapter = new $.jqx.dataAdapter(globalSource);

	$("#globalGoods")
			.jqxDataTable(
					{
						width : "100%",
						source : globaldataAdapter,
						pageable : true,
						pageSize : 15,
						serverProcessing : true,
						pagerButtonsCount : 10,
						columnsResize : true,
						sortable : true,
						columns : [
								{
									text : "序号",
									width : 50,
									cellsRenderer : function(row) {
										return (row + 1).toString();
									}
								},
								{
									text : "名称",
									dataField : "name"
								},
								{
									text : "操作",
									cellsRenderer : function(row, column, value, rowData) {
										if (rowData.qqgBoutique === false) {
											return "<input type='button' onclick=\"isBoutique('" + rowData.uuid + "', 'true')\" class='btn-sm btn-primary' value='设置推荐' />";
										} else {
											return "<input type='button' onclick=\"isBoutique('" + rowData.uuid + "', 'false')\" class='btn-sm btn-warning' value='取消推荐' />";
										}
									}
								} ],
					});
	//	
	//	
	// $("#combobox2").jqxComboBox({
	// selectedIndex : 0,
	// source : globaldataAdapter,
	// displayMember : "name",
	// valueMember : "uuid",
	// width : 400,
	// height : 25,
	// popupZIndex : 20000000
	// });
}
function isBoutique(uuid,type){
	$.ajax({
		url:"qqg/updateQQGBoutique.do",
		data:{"uuid" : uuid, "isBoutique" : type},
		type:"post",
		success:function(result){
			layer.msg(result.msg);
			update($("#globalGoods"));
		}
	});
}
